<template>
  <div class="login_container">
    <div class="login">
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm">
        <el-form-item label="账号" prop="userName">
          <el-input class="el-input" type="text" v-model="ruleForm.userName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="passWord">
          <el-input class="el-input" type="password" v-model="ruleForm.passWord" autocomplete="off" @keydown.enter.native="submitForm('ruleForm')"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          userName: '',
          passWord: ''
        },
        rules: {
          userName: [
            { required: true, message: '请输入账户/手机号/邮箱', trigger: 'blur' }
          ],
          passWord: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid && Object.values(this.ruleForm).every(item => item)) {
            // this.$message('登录成功');
            this.$router.push('/base/')
          } else {
            // this.$message('请输入账户 或 密码')
            // console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style scoped>
  .login_container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background-color: #b3c0d1;
  }

  .demo-ruleForm {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24%;
    height: 20%;
    padding-top: 20px;
    background-color: #e9eef3;
  }

  .el-input {
    width: calc(100% - 80px);
  }
</style>